package Java.com.hcj.service;

import Java.com.hcj.dao.TableDao;
import Java.com.hcj.entity.Table;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

/**
 * Created by an on 2016/9/23.
 */
public class TableService implements TableDao{


    @Override
    public List<Table>  findByName(Table tables) {
        String resource="Java/com/hcj/Configure.xml";
        Reader reader=null;
        SqlSessionFactory ssf=null;
        SqlSession session=null;
        List<Table>   table=null;
        try {
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            ssf = builder.build(reader);
            session=ssf.openSession();
            TableDao tableDao=session.getMapper(TableDao.class);
            table=tableDao.findByName(tables);
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            session.close();
        }
        return table;
    }


}
